
@extends ('layouts/app')

@section('content')

<div class="weui-grids detail">
    <a href="" class="weui-grid js_grid  detail-a">
        <div class="weui-grid__icon">
            <svg class="icon f56" aria-hidden="true">
                <use xlink:href="#icon-tubiao-10"></use>
            </svg>
        </div>
        <p class="weui-grid__label f24">
            账户余额(元)
        </p>
        <p class="weui-grid__label f48 money">
            100.00
        </p>
    </a>
    <a href="" class="weui-grid js_grid detail-b">
        <div class="weui-grid__icon">
            <svg class="icon f56" aria-hidden="true">
                <use xlink:href="#icon-tubiao-11"></use>
            </svg>
        </div>
        <p class="weui-grid__label f24">
            积分
        </p>
        <p class="weui-grid__label f48 point">
            0.0
        </p>
    </a>
</div>
{{--弹出按钮--}}
<div class="weui-cells">
    <a class="weui-cell weui-cell_access next1" href="javascript:;">

        <div class="weui-cell__bd">
            <p class="f30">提现</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>

    <a class="weui-cell weui-cell_access next2" href="javascript:;">

        <div class="weui-cell__bd">
            <p class="f30">充值</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    <a class="weui-cell weui-cell_access" id="Top-up_1" href="/mobile/prepaid">

        <div class="weui-cell__bd">
            <p class="f30">充值卡充值</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    <a class="weui-cell weui-cell_access " href="/mobile/businesf">

        <div class="weui-cell__bd">
            <p class="f30">银行卡管理</p>
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    {{--<a class="weui-cell weui-cell_access" id="Top-up" href="javascript:;">--}}
        {{--<div class="weui-cell__bd">--}}
            {{--<p class="f30">分享挣佣金</p>--}}
        {{--</div>--}}
        {{--<div class="weui-cell__ft"></div>--}}
    {{--</a>--}}
</div>
{{--弹出样式--}}

<div id="full1" class="weui-popup__container">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="remaining"></div>{{--空元素--}}
        <div class="weui-pay">
            <div class="weui-pay-inner">
                {{--<div>到账银行卡</div>--}}
                <div class="weui-panel__ft">
                    <a id="bank" href="javascript:void(0);" class="weui-cell weui-cell_access weui-cell_link no-border">
                        <div class="weui-cell__bd">到账银行卡</div>
                        <span class="weui-cell__ft bank-info">中国工商银行（9528）</span>
                        <input type="hidden" name="id" value="">
                    </a>
                </div>
            </div>
            <div class="weui-pay-inner">
                <h1 class="weui-pay-title">提现金额</h1>
                <div class="weui-pay-input">
                    <strong class="weui-pay-strong">￥</strong>
                    <input type="number" name="money" class="weui-pay-inputs" placeholder="请输入金额"></div>
                <div class="weui-pay-intro">每日交易金额10000.0元</div>
            </div>
        </div>
        <div class="demos-content-padded">
            <a href="javascript:;" class="weui-btn weui-btn_primary_a btn-confirm f30">提现</a>
            <a href="javascript:;" class="weui-btn weui-btn_white f30 close-popup">取消</a>
        </div>
    </div>
</div>
<div id="full2" class="weui-popup__container">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="remaining"></div>{{--空元素--}}
        <div class="weui-pay">
            <div class="weui-pay-inner">
                <h1 class="weui-pay-title">充值金额</h1>
                <div class="weui-pay-input"> <strong class="weui-pay-strong">￥</strong>
                    <input type="number" name="money" class="weui-pay-inputs" placeholder="请输入金额"></div>
                <div class="weui-pay-intro ">每日交易金额1000.0元</div>
            </div>
        </div>
        <div class="demos-content-padded">
            <a href="javascript:;" class="weui-btn weui-btn_primary_a btn-confirm f30">下一步</a>
            <a href="javascript:;" class="weui-btn weui-btn_white f30 close-popup">取消</a>
        </div>
    </div>
</div>
<script>
//  点击事件
var id = getRequest().id;
var bankList = [];
var _token = $("input[name='_token']").val();
$(".next1").click(function () {
    $("#full1").popup();
    // 获取银行卡列表
    getBankList();
});

$(".next2").click(function () {
    $("#full2").popup();
});

//点击事件
$("#Top-up").click(function () {
    location.href = '/mobile/refillcard?id=' + id;
});

//点击关闭事件
//$(".btn-confirm").click(function(){
//    $.closePopup();
//})
    var userInfo = Storage.get("userInfo");
    if (userInfo.status) {
       userInfo = JSON.parse(userInfo.value);
       console.log("userInfo", userInfo);

       $(".money").text(userInfo[0].money);
       $(".point").text(userInfo[0].point);
    }

    // 充值
    $("#full2 .btn-confirm").click(function () {
        var money = $("#full2 input[name='money']").val();

        console.log('trn', money);
        if (!money || money < 10) {
            return $.toast("金额必须大于等于10！", "text");
        }

        $.post("/api/onlineCharge", {money: money}, function (res) {
            if (typeof res === 'string') {
                res = JSON.parse(res);
            }

            $.toast(res.info, 'text');

            if (res.code == 200) {
                location.href = '/mobile/payment?id=' + res.data.order_id + '&money=' + res.data.money + '&order_type=' + res.data.order_type;
            }
        });
    });

    // 提现
    $("#full1 .btn-confirm").click(function () {
        console.log("我要提现");


        var money = $("#full1 input[name='money']").val();

        if (!money || money < 10) {
            return $.toast("金额必须大于等于10！", "text");
        }
        var bid = $("input[name='id']").val();

        $.post("/api/user/withdraw", {money: money, id: bid}, function (res) {
            if (typeof res === 'string') {
                res = JSON.parse(res);
            }

            if (res.code == 205) {
                $.modal({
                    title: "提示",
                    text: res.info,
                    buttons: [
                        {
                            text: "去实名",
                            onClick: function () {
                                location.href = "/mobile/realname"
                            }
                        },
                        { text: "取消", className: "default", onClick: function(){ console.log(3)} },
                    ]
                });
            } else {
                $.alert(res.info, function () {
                    if (res.code == 200) {
                        getUserInfo(_token, function () {
                            location.reload();
                        });
                    }
                });
            }




        });
    });

    function getBankList () {
        $.post("/api/shop/showCard", { }, function (res) {
            if (typeof res === 'string') {
                res = JSON.parse(res);
            }
            console.log("res", res);
            setBank(res.data[0]);
            // 格式化
            bankList = setBankData(res.data);
            // 选择银行卡
            $("#bank").select({
                title: "选择手机",
                items: bankList,
                onClose: function (r) {
                    console.log("r", r);

                    // 拆分数据，去显示
                    var obj = {};
                    var strArr = r.data.titles.split("(");

                    obj['bank'] = strArr[0];
                    obj['account_number'] = strArr[1].replace(')', '');
                    obj['id'] = r.data.values;

                    console.log("strArr", strArr);
                    // 去显示
                    setBank(obj);
                }
            });
        });
    }

    // 设置到账的银行卡
    function setBank (b) {
        console.log("b.account_number", typeof b.account_number);
        var num = b.account_number,
            fourNum = num.slice(-4);

        console.log("fourNum", fourNum);

        var bankInfo = b.bank + '(' + fourNum + ')';

        $(".bank-info").text(bankInfo);
        $("input[name='id']").val(b.id);
    }

    // 格式化银行卡列表数据
    function setBankData (data) {
        var arr = [];
        for (var i = 0, len = data.length; i < len; i++) {
            data[i].account_number = data[i].account_number.substr(0,6) + "********" + data[i].account_number.substr(-4);
            arr.push({title: data[i].bank + '(' + data[i].account_number + ')', value: data[i].id});
        }

        return arr;
    }
    //明细
    $("#remainin").click(function () {
        var userInfo = Storage.get("userInfo");
        if(userInfo.status){
            userInfo =JSON.parse(userInfo.value);
        }
        location.href = "/mobile/remainin?uid=" + userInfo[0].id;
    });

</script>
@endsection

